package com.jinglin.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private int code;
    private String message;
    private T data;
    private String token;
    private long total;

    public Result(T data) {
        this.code = 0;
        this.message = "success";
        this.data = data;
    }
    public Result(T data,long total) {
        this.code = 0;
        this.message = "success";
        this.data = data;
        this.total = total;
    }
    public Result(String  token) {
        this.code = 0;
        this.message = "success";
        this.token = token;
    }

    public Result(T data,int code, String message) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }
    public static <T> Result<T> success(String  token) {
        return new Result<>(token);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(500, message);
    }

    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, message);
    }
}

